package com.example.wechat2

import android.content.ContentValues
import android.content.Context
import android.os.Bundle
import android.util.Log
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.LinearLayoutManager
import com.example.wechat.ChatAdapter
import kotlinx.android.synthetic.main.fragment_chat.*
import kotlinx.android.synthetic.main.fragment_friends.*

class FriendsFragment : Fragment() {

    val TAG = "@@FriendsFragment"

    data class FriendsInfo(val fri_name:String,val fri_head:Int)

    val friendsInfos = arrayListOf<FriendsInfo>()

    override fun onCreateView(
        inflater: LayoutInflater, container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        return inflater.inflate(R.layout.fragment_friends, container, false)

    }


    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        Log.d(TAG,"onViewCreated")

        initData()
        recycler_fri.adapter = FriAdapter(friendsInfos)
        recycler_fri.layoutManager = LinearLayoutManager(this.activity)


    }

    override fun onAttach(context: Context) {
        super.onAttach(context)
        Log.d(TAG,"onAttach")
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        Log.d(TAG,"onCreate")

    }



    override fun onActivityCreated(savedInstanceState: Bundle?) {
        super.onActivityCreated(savedInstanceState)
        Log.d(TAG,"onActivityCreated")
    }



    override fun onStart() {
        super.onStart()
        Log.d(TAG,"onStart")
    }

    override fun onResume() {
        super.onResume()
        Log.d(TAG,"onResume")
    }

    override fun onPause() {
        super.onPause()
        Log.d(TAG,"onPause")
    }

    override fun onStop() {
        super.onStop()
        Log.d(TAG,"onStop")
    }

    override fun onDestroyView() {
        super.onDestroyView()
        Log.d(TAG,"onDestroyView")
    }

    override fun onDestroy() {
        super.onDestroy()
        Log.d(TAG,"onDestroy")
    }

    override fun onDetach() {
        super.onDetach()
        Log.d(TAG,"onDetach")
    }

    private fun initData() {
        Log.d(ContentValues.TAG,"initdata")


        for(i in 0..5) {
            val friend = FriendsInfo("CandyTang", R.mipmap.head2)
            friendsInfos.add(friend)
            val friend1 = FriendsInfo("LuoRainStar", R.mipmap.head3)
            friendsInfos.add(friend1)
            val friend2 = FriendsInfo("木子李", R.mipmap.head4)
            friendsInfos.add(friend2)
            val friend3 = FriendsInfo("乐乐", R.mipmap.head5)
            friendsInfos.add(friend3)
        }

    }


}



